//
//  BaseAnnotationView.m
//  jetour_line
//
//  Created by aha on 2023/6/17.
//
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height
#define PX(x) 375.0*x/SCREENWIDTH
#define FONT(x) [UIFont fontWithName:@"PingFang SC" size:PX(x)]

#import "BaseAnnotationView.h"
#import "JetourLinePlugin.h"
@implementation BaseAnnotationView


- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setBounds:CGRectMake(0.f, 0.f, PX(32), PX(32))];
    }
    return self;
}
- (void)setDic:(NSDictionary *)dic{
    NSString *type = [dic objectForKey:@"type"];
    if([type isEqualToString:@"commonDetail"]){
        [self setBounds:CGRectMake(0.f, 0.f, PX(32), PX(32))];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, PX(32), PX(32))];
        imageView.image = [UIImage imageNamed:[[JetourLinePlugin getRegister] lookupKeyForAsset:@"packages/jetour_line/res/lsgj_mappoi.png"]];//默认的图片资源
        [self addSubview:imageView];
        
        
        UITextView *indexTxt = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, PX(32), PX(32))];
        indexTxt.backgroundColor = [UIColor clearColor];
        NSString *index = [NSString stringWithFormat:@"%d",[[dic objectForKey:@"index"] intValue]];
        indexTxt.text = index;
        [indexTxt setTextAlignment:NSTextAlignmentCenter];
        [indexTxt setTextColor: [UIColor colorWithRed:0/255.0 green:161/255.0 blue:152/255.0 alpha:255/255.0]];
        [self addSubview:indexTxt];
    }else if([type isEqualToString:@"lineDetail"]){
        [self setBounds:CGRectMake(0.f, 0.f, PX(42), PX(42))];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, PX(42), PX(42))];
        imageView.image = [UIImage imageNamed:[[JetourLinePlugin getRegister] lookupKeyForAsset:@"packages/jetour_line/res/lsgj_icon_mappotr.png"]];//默认的图片资源
        [self addSubview:imageView];
        
        UITextView *indexTxt = [[UITextView alloc]initWithFrame:CGRectMake(0, PX(1), PX(42), PX(20))];
        indexTxt.backgroundColor = [UIColor clearColor];
        NSString *index = [NSString stringWithFormat:@"%d",[[dic objectForKey:@"index"] intValue]];
        indexTxt.text = index;
        [indexTxt setTextAlignment:NSTextAlignmentCenter];
        [indexTxt setTextColor: [UIColor colorWithRed:0/255.0 green:161/255.0 blue:152/255.0 alpha:255/255.0]];
        [self addSubview:indexTxt];
    }
}
@end
